package com.yonyou.crm.sact.schedule.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yonyou.crm.common.biz.service.BaseBizServiceImpl;
import com.yonyou.crm.common.exception.CrmBusinessException;
import com.yonyou.crm.sact.schedule.entity.ScheduleObjectVO;
import com.yonyou.crm.sact.schedule.entity.ScheduleTypeEnum;
import com.yonyou.crm.sys.modules.entity.BiztypeEnum;
import com.yonyou.crm.sys.modules.entity.MtObjTypeEnum;

@Service
public class ScheduleObjectBizServiceImpl extends BaseBizServiceImpl<ScheduleObjectVO>{
	
	public List<ScheduleObjectVO> getList(Map<String, Object> param){
		List<ScheduleObjectVO> scheduleObjectList = new ArrayList<ScheduleObjectVO>();
		dao.selectVoList(ScheduleObjectVO.class, "getScheduleObjectList", param);
		return scheduleObjectList;
	}
	
	public ScheduleObjectVO save(ScheduleObjectVO scheduleObject){
		return super.saveVO(scheduleObject);
	}
	
	public ScheduleObjectVO update(ScheduleObjectVO scheduleObject){
		return super.updateVO(scheduleObject);
	}
	
	public int deleteScheduleObjectByIDs(String[] ids){
		return dao.batchDelete(ScheduleObjectVO.class, ids);
	}
	
	/**
	 * 转换日程类型(将String转换Integer)
	 * @param String scheduleTypeName
	 * @return Integer scheduleType
	 */
	public static Integer getScheduleType(String scheduleTypeName) {
		Integer scheduleType = 0;
		for (ScheduleTypeEnum scheduleTypeEnum : ScheduleTypeEnum.values()) {
			if (scheduleTypeEnum.getName().equals(scheduleTypeName)) {
				scheduleType = scheduleTypeEnum.getValue();
			}
		}
    	if (scheduleType == 0) {
    		throw new CrmBusinessException("非法日程类型");
    	}
		return scheduleType;
	}
	
	/**
	 * 转换业务对象类型(将String转换Integer)
	 * @param String objTypeStr
	 * @return Long objType
	 */
	public static Long getObjType(String objTypeStr) {
		Long objType = (long)0;
		for (MtObjTypeEnum objTypeEnum : MtObjTypeEnum.values()) {
			if (objTypeEnum.getName().equals(objTypeStr)) {
				objType = objTypeEnum.getValue();
			}
		}
		if (objType == (long)0) {
			throw new CrmBusinessException("非法对象类型");
		}
		return objType;
	}
	
	/**
	 * 转换业务对象子类型(将String转换Integer)
	 * @param String bizObjTypeStr
	 * @return Integer bizObjType
	 */
	public static Long getBizObjType(String bizObjTypeStr) {
		Long bizObjType = (long)0;
		for (BiztypeEnum bizObjTypeEnum : BiztypeEnum.values()) {
			if (bizObjTypeEnum.getName().equals(bizObjTypeStr)) {
				bizObjType = bizObjTypeEnum.getValue();
			}
		}
		if (bizObjType == (long)0) {
			throw new CrmBusinessException("非法对象类型");
		}
		return bizObjType;
	}
}
